from django.shortcuts import render, redirect, reverse
from app.myAppPack.myWordcloud import creater
import os


# Create your views here.
def home(request):
    return render(request, 'index.html')
    pass


def gameset(request):
    if request.POST:
        opt = request.POST.get('options')
        url = reverse('gamemain', kwargs={'opt': opt})
        return redirect(url)
        pass
    else:
        return render(request, 'gameset.html', {'list': list(range(3, 8))})
        pass
    pass


def learnmore(request):
    return render(request, 'learnmore.html')
    pass


def gamemain(request, opt):
    return render(request, 'gamemain.html', {'data': list(range(opt)),'num': int(opt)})
    pass


def worldcloud(request):
    if request.POST:
        longstr = request.POST.get('longstr')
        opt = int(request.POST.get('options'))
        address = os.getcwd().split(os.sep)
        address.append('static')
        address.append('app')
        address.append('tem')
        address_str = str(os.sep).join(address)
        filename = creater(longstr, address_str, opt)
        return render(request, 'worldcloud.html', {'img': 'app' + os.sep + 'tem' + os.sep + '{0}'.format(filename)})
        pass
    else:
        return render(request, 'worldcloud.html',
                      {'img': 'app' + os.sep + 'img' + os.sep + '662e3567-c0e8-11ea-916a-303a64af97.png'})
        pass
    pass


def EngTex(request):
    data = [
        {'word': 'a', 'tips': "安", 'site': '一'},
        {'word': 'b', 'tips': "辫", 'site': '一'},
        {'word': 'c', 'tips': "蚕", 'site': '一'},
        {'word': 'd', 'tips': "殿", 'site': '一'},
        {'word': 'e', 'tips': "嫩", 'site': '二'},
        {'word': 'f', 'tips': "坊", 'site': '一'},
        {'word': 'g', 'tips': "根", 'site': '一'},
        {'word': 'e', 'tips': "稳", 'site': '二'},
        {'word': 'h', 'tips': "吼", 'site': '一'},
        {'word': 'i', 'tips': "麦", 'site': '三'},
        {'word': 'j', 'tips': "蒋", 'site': '一'},
        {'word': 'k', 'tips': "扣", 'site': '一'},
        {'word': 'l', 'tips': "朗", 'site': '一'},
        {'word': 'm', 'tips': "妙", 'site': '一'},
        {'word': 'n', 'tips': "鸟", 'site': '一'},
        {'word': 'o', 'tips': "沃", 'site': '二'},
        {'word': 'p', 'tips': "篇", 'site': '一'},
        {'word': 'q', 'tips': "瞧", 'site': '一'},
        {'word': 'r', 'tips': "揉", 'site': '一'},
        {'word': 's', 'tips': "僧", 'site': '一'},
        {'word': 't', 'tips': "调", 'site': '一'},
        {'word': 'u', 'tips': "园", 'site': '二'},
        {'word': 'w', 'tips': "闻", 'site': '一'},
        {'word': 'x', 'tips': "校", 'site': '一'},
        {'word': 'y', 'tips': "盐", 'site': '一'},
        {'word': 'z', 'tips': "赞", 'site': '一'},
    ]
    return render(request, 'EinglishText.html', {'data': data})
    pass

def blog(request):
    return render(request, 'theBlog.html')
    pass